package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Security;
import com.hengxinguotong.zhihuichengjian.treeview.RecyclerAdapter;
import com.hengxinguotong.zhihuichengjian.utils.Constants;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liux on 2017/3/7.
 */

public class SecurityListAdapter extends RecyclerAdapter<Security, SecurityListAdapter.SecurityViewHolder> {
    private int type;

    public SecurityListAdapter(Context context, List<Security> dataList) {
        super(context, dataList);
    }

    public void setType(int type) {
        this.type = type;
    }

    @Override
    public SecurityViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_security, null);
        return new SecurityViewHolder(view);
    }

    @Override
    public void onBindViewHolder(SecurityViewHolder holder, int position) {
        holder.bindData(position);
    }


    public class SecurityViewHolder extends RecyclerAdapter.BaseViewHolder<Security>{
        @BindView(R.id.state_iv)
        ImageView stateIv;
        @BindView(R.id.state_tv)
        HXTextView stateTv;
        @BindView(R.id.content)
        HXTextView content;
        @BindView(R.id.person_liable_tv)
        HXTextView personLiableTv;
        @BindView(R.id.person_tv)
        HXTextView personTv;
        @BindView(R.id.company_tv)
        HXTextView companyTv;
        @BindView(R.id.data_tv)
        HXTextView dataTv;
        @BindView(R.id.order_no_tv)
        HXTextView orderNoTv;

        public SecurityViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void bindData(final int position) {
            Security security = dataList.get(position);
            dataTv.setText(security.getBusinessDate());
            content.setText(security.getItems());
            personLiableTv.setText(security.getContactName());
            personTv.setText(security.getCreateByName());
            if(security.getProjectCompanyName() != null && !Utils.isEmpty(security.getProjectCompanyName())){
                if(security.getProjectCompanyName().length() > 12){
                    companyTv.setText(security.getProjectCompanyName().substring(0, 12) + "...");
                }else{
                    companyTv.setText(security.getProjectCompanyName());
                }
            }else{
                companyTv.setText("无施工单位");
            }
            switch (security.getStatus()) {
                case 1:
                    stateIv.setImageResource(R.mipmap.small_green);
                    stateTv.setText("检测通过");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_71e5a2));
                    break;
                case 2:
                    stateIv.setImageResource(R.mipmap.small_yellow);
                    stateTv.setText("检测警告");
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_ffc065));
                    break;
                case 3:
                    stateIv.setImageResource(R.mipmap.small_red);
                    if(type== Constants.QUALITY){
                        stateTv.setText("质量整改");
                    }else if (type == Constants.CIVILIZED_CONSTRUCTION_SUPERVISE){
                        stateTv.setText("文明施工整改");
                    } else{
                        stateTv.setText("安全整改");
                    }
                    stateTv.setTextColor(context.getResources().getColor(R.color.color_f1636a));
                    break;
            }
            orderNoTv.setText(security.getOrderNo());
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    clickListener.onClick(position);
                }
            });
        }
    }
}
